#include "Fou.h"

#include <string>

using std::string;

string Fou::nom("Fou");

Fou::Fou(Echiquier * E, Position P, bool couleur):Piece(E, P, couleur)
{
	object = new FouGL (this,couleur) ;
}

Fou::~Fou (){
	if (object){
		delete object;
		object = NULL ;
	}	
}
char Fou::rendu() const
{
	return (c?'F':'f') ;
}

const string& Fou::toString()const
{
	return nom;
}

void Fou::majAtk()
{
    atk.clear();
	bool cont(true);
	Position tmp(p);

	while(--tmp.getC() >= 0 && --tmp.getL() >= 0 && cont)
	{
			atk.push_back(tmp);
			cont = !e->getPiece(tmp);
	}

	cont = true; tmp = p;
	while(--tmp.getC() >= 0 && ++tmp.getL() < 8 && cont)
	{
			atk.push_back(tmp);
			cont = !e->getPiece(tmp);
	}

	cont = true; tmp = p;
	while(++tmp.getC() < 8 && --tmp.getL() >= 0 && cont)
	{
			atk.push_back(tmp);
			cont = !e->getPiece(tmp);
	}

	cont = true; tmp = p;
	while(++tmp.getC() < 8 && ++tmp.getL() < 8 && cont)
	{
			atk.push_back(tmp);
			cont = !e->getPiece(tmp);
	}
}

void Fou::majDeplacements()
{
    cloue = false;
	bool cont(true);
	Position tmp(p);

	dep.clear();

	while(--tmp.getC() >= 0 && --tmp.getL() >= 0 && cont)
		if((cont = !e->getPiece(tmp)) || (e->getPiece(tmp)->estBlanc() != estBlanc()))
			dep.push_back(tmp);

	cont = true; tmp = p;
	while(--tmp.getC() >= 0 && ++tmp.getL() < 8 && cont)
		if((cont = !e->getPiece(tmp)) || (e->getPiece(tmp)->estBlanc() != estBlanc()))
			dep.push_back(tmp);

	cont = true; tmp = p;
	while(++tmp.getC() < 8 && --tmp.getL() >= 0 && cont)
		if((cont = !e->getPiece(tmp)) || (e->getPiece(tmp)->estBlanc() != estBlanc()))
			dep.push_back(tmp);

	cont = true; tmp = p;
	while(++tmp.getC() < 8 && ++tmp.getL() < 8 && cont)
		if((cont = !e->getPiece(tmp)) || (e->getPiece(tmp)->estBlanc() != estBlanc()))
			dep.push_back(tmp);
}

Piece* Fou::clone(Echiquier* ne) const
{
    Piece* clone = new Fou(ne,p,c);
	clone->getDep() = dep;
	clone->getAtk() = atk;
	clone->getpAtk() = pAtk;
	clone->getpDef() = pDef;
	return clone;
}
